package com.feishi.core.util.bitbyte;

import java.io.*;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2019-06-17
 * Time: 上午10:59
 */
public class CsvUtil {
    public static List<Map<String,String>> readListWithTitle(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String titleStr = reader.readLine();

        String[] titles = titleStr.split(",");
        String line;
        List<Map<String,String>> result=new ArrayList<>();
        while((line=reader.readLine())!=null){
            Map<String,String> item=new HashMap<>();
            String items[] = line.split(",");
            for (int i = 0; i < items.length && i < titles.length; i++) {
                item.put(titles[i],items[i]);
            }
            result.add(item);
        }
        return result;
    }
    public static List<List<String>> readList(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        List<List<String>> result=new ArrayList<>();
        while((line=reader.readLine())!=null){
            List<String> item= Arrays.asList(line.split(","));
            result.add(item);
        }
        return result;
    }

}
